<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<!-- 顶部导航 -->
		<custom-navber titleSize="28rpx"
			:userGender="data.activity_info.publisher_gender"
			:imgUrl="data.activity_info.publisher_avatar || 'https://mp-22f314fc-fd0f-43b9-886e-ac79fe32303c.cdn.bspapp.com/image/default-avatar.jpg'"
			:title="data.activity_info.publisher_nickname"></custom-navber>
		<!-- #endif -->
		<view class="ping-30 bottom-index " :style="{paddingTop:menuObject.top + menuObject.height + 8 +'px'}">
			<view class="fw-600 fs-36 mt-30">{{data.notice_title}}</view>
			<view class="mt-30">
				<view @click="$NavigateTo('/pages/detail/detail?id=' + data.activity_info._id)"
					class="flex-dir-row ali-item-cen mr-20 flex-shrink-0">
					<view class="bac-col-00b activity-view">
						<image :src="data.activity_info.imgs[0].src" class="activity-image" mode="aspectFill" />
						<view class="fs-26 ml-10 col-f text-element-1 flex-1">{{data.activity_info.name}}</view>
					</view>
				</view>
				<view class="flex-dir-row ali-item-cen mt-10">
					<view class="fs-28 col-87">{{ $formatDateTime(data.notice_time) }}</view>
				</view>
			</view>
			<view class="mt-30 fs-30">
				<mp-html :content="data.notice_content"></mp-html>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
	export default {
		data() {
			return {
				// #ifdef MP-WEIXIN
				menuObject: uni.getMenuButtonBoundingClientRect(),
				// #endif
				// #ifndef MP-WEIXIN
				menuObject: 0,
				// #endif
				data: {},
			}
		},
		computed: {
			userInfo() {
				return store.userInfo //用户信息
			},
		},
		onLoad(options) {
			try {
				if (!options.data) {
					console.error("options.data 为空");
					return;
				}
				// 先解码，再解析
				const decodedData = decodeURIComponent(options.data);
				this.data = JSON.parse(decodedData);
				// 判断消息是否未读，如果未读则修改为已读状态
				if (!this.data.user_read_status_array.includes(this.userInfo._id)) {
					this.$Route('update-private-data', true).updateActivityNoticeReadStatus(this.data._id).then((res) => {
						if (res.code == 200) {
							this.getOpenerEventChannel().emit('refresh', '')
						}
					}).catch((err) => {
						console.error('遇到错误:', err); // 打印错误信息
					});
				}
			} catch (error) {
				console.error("JSON 解析错误:", error, options.data);
			}
		},
		methods: {}
	}
</script>

<style lang="scss">
	.activity-view {
		height: 45rpx;
		line-height: 45rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		padding-right: 10rpx;
	}

	.activity-image {
		width: 45rpx;
		height: 45rpx;
		border-top-left-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}
</style>